<?php

class Skjb_Search_Xapian_QueryParser
{
    public $_cPtr=null;

    const FLAG_BOOLEAN = 1;

    const FLAG_PHRASE = 2;

    const FLAG_LOVEHATE = 4;

    const FLAG_BOOLEAN_ANY_CASE = 8;

    const FLAG_WILDCARD = 16;

    const FLAG_PURE_NOT = 32;

    const FLAG_PARTIAL = 64;

    const FLAG_SPELLING_CORRECTION = 128;

    const FLAG_SYNONYM = 256;

    const FLAG_AUTO_SYNONYMS = 512;

    const FLAG_AUTO_MULTIWORD_SYNONYMS = QueryParser_FLAG_AUTO_MULTIWORD_SYNONYMS;

    const FLAG_DEFAULT = QueryParser_FLAG_DEFAULT;

    const STEM_NONE = 0;

    const STEM_SOME = QueryParser_STEM_SOME;

    const STEM_ALL = QueryParser_STEM_ALL;

    function __construct() {
        $this->_cPtr=new_QueryParser();
    }

    function set_stemmer($stemmer) {
        QueryParser_set_stemmer($this->_cPtr,$stemmer);
    }

    function set_stemming_strategy($strategy) {
        QueryParser_set_stemming_strategy($this->_cPtr,$strategy);
    }

    function set_stopper($stop=null) {
        QueryParser_set_stopper($this->_cPtr,$stop);
    }

    function set_default_op($default_op) {
        QueryParser_set_default_op($this->_cPtr,$default_op);
    }

    function get_default_op() {
        return QueryParser_get_default_op($this->_cPtr);
    }

    function set_database($db) {
        QueryParser_set_database($this->_cPtr,$db);
    }

    function parse_query($query_string,$flags=null,$default_prefix=null) {
        switch (func_num_args()) {
        case 1: $r=QueryParser_parse_query($this->_cPtr,$query_string); break;
        case 2: $r=QueryParser_parse_query($this->_cPtr,$query_string,$flags); break;
        default: $r=QueryParser_parse_query($this->_cPtr,$query_string,$flags,$default_prefix);
        }
        return is_resource($r) ? new Skjb_Search_Xapian_Query($r) : $r;
    }

    function add_prefix($field,$prefix) {
        QueryParser_add_prefix($this->_cPtr,$field,$prefix);
    }

    function add_boolean_prefix($field,$prefix) {
        QueryParser_add_boolean_prefix($this->_cPtr,$field,$prefix);
    }

    function stoplist_begin() {
        $r=QueryParser_stoplist_begin($this->_cPtr);
        return is_resource($r) ? new Skjb_Search_Xapian_TermIterator($r) : $r;
    }

    function stoplist_end() {
        $r=QueryParser_stoplist_end($this->_cPtr);
        return is_resource($r) ? new Skjb_Search_Xapian_TermIterator($r) : $r;
    }

    function unstem_begin($term) {
        $r=QueryParser_unstem_begin($this->_cPtr,$term);
        return is_resource($r) ? new Skjb_Search_Xapian_TermIterator($r) : $r;
    }

    function unstem_end($arg1) {
        $r=QueryParser_unstem_end($this->_cPtr,$arg1);
        return is_resource($r) ? new Skjb_Search_Xapian_TermIterator($r) : $r;
    }

    function add_valuerangeprocessor($vrproc) {
        QueryParser_add_valuerangeprocessor($this->_cPtr,$vrproc);
    }

    function get_corrected_query_string() {
        return QueryParser_get_corrected_query_string($this->_cPtr);
    }

    function get_description() {
        return QueryParser_get_description($this->_cPtr);
    }
}